<?php

namespace app\model;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class GameSell extends Base
{

    protected $connection;
    protected $table = 'game_sell';

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->connection = config('database.connections.biqi_game.database');
    }

    public function content(): Attribute
    {
        return Attribute::make(
            get: fn(string $value) => json_decode($value, true),
            set: fn(array $value) => json_encode($value),
        );
    }

    public function GameSellOrderBind(): HasMany
    {
        return $this->hasMany(GameSellOrder::class, 'sell', 'ulid');
    }

    public function GameAuthorizationBind(): BelongsTo
    {
        return $this->belongsTo(GameAuthorization::class, 'game', 'ulid')->where('state', 1);
    }

}